/*
 * Copyright (C) 2015-2017 Alibaba Group Holding Limited
 */
#ifndef OTA_VERIFY_H
#define OTA_VERIFY_H
#include "ota_hal_digest.h"

#define OTA_HASH_NONE                     (0)
#define OTA_SHA256                        (1)
#define OTA_MD5                           (2)

#define OTA_SIGN_BUF_SIZE                 (256)
#define OTA_HASH_VALUE_SIZE               (65)
#define OTA_SIGN_BITNUMB                  (2048)

/* Verify */
typedef struct {
    char sign_enable;
    unsigned char sign_value[OTA_SIGN_BUF_SIZE];
}ota_sign_t;

typedef struct
{
    unsigned char   hash_method;
    char            hash_value[OTA_HASH_VALUE_SIZE];
} ota_hash_t;

typedef struct {
    unsigned char hash_method;
    union {
        ota_md5_context md5_ctx;
        ota_sha256_context sha256_ctx;
    };
} ota_hash_ctx_t;
/* Hash */
int ota_hash_init(ota_hash_ctx_t *ctx, unsigned char type);
int ota_hash_update(ota_hash_ctx_t *ctx, const unsigned char *buf, unsigned int len);
int ota_hash_final(ota_hash_ctx_t *ctx, unsigned char *dgst);
int ota_check_hash(unsigned char type, char *src, char *dst);
int ota_check_image(unsigned int size);

/* Signature */
int ota_verify_rsa(unsigned char *sign_dat, const char *hash_dat, unsigned char hash_type);
#endif /*OTA_VERIY_H*/

